<template>
<el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path" unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b">
  <router-link to="/main">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
      <h1 class="sidebar-title">后台管理</h1>
    </div>
  </router-link>
  <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
    <template slot="title">
      <i class="iconfont" :class="menu.icon"></i>
      <span>{{menu.menuname}}</span>
    </template>
    <el-menu-item-group :title="menu.menuname">
      <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.url" :key="chmenu.menuid">
        <i class="iconfont" :class="chmenu.icon"></i>
        <span>{{chmenu.menuname}}</span>
      </el-menu-item>
    </el-menu-item-group>
  </el-submenu>
</el-menu>
</template>

<script>
export default {
  name: "leftnav",
  data() {
    return {
      collapsed: false,
      allmenu: [],
    };
  },
  // 创建完毕状态(里面是操作)
  created() {
    // 获取图形验证码
    let res = {
      success: true,
      data: [{
          menuid: 1,
          icon: "li-icon-xiangmuguanli",
          menuname: "农户管理",
          url: null,
          menus: [{
              menuid: 2,
              icon: "icon-cat-skuQuery",
              menuname: "农户列表",
              url: "farmer/index",
              menus: null,
            },
            {
              menuid: 3,
              icon: "icon-cat-skuQuery",
              menuname: "农户审核",
              url: "farmer/auditList",
              menus: null,
            },
          ],
        },
        {
          menuid: 8,
          icon: "li-icon-shangchengxitongtubiaozitihuayuanwenjian91",
          menuname: "产品管理",
          url: null,
          menus: [{
              menuid: 9,
              icon: "icon-provider-manage",
              menuname: "产品列表",
              url: "product/index",
              menus: null,
            }
          ],
        },
      ],
      msg: "success",
    };
    this.allmenu = res.data;

    // 监听
    this.$root.Bus.$on("toggle", (value) => {
      this.collapsed = !value;
    });
  },
};
</script>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}

.el-menu-item-group__title {
  padding: 0px;
}

.el-menu-bg {
  background-color: #1f2d3d !important;
}

.el-menu {
  border: none;
}

.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}

.logoimg {
  height: 40px;
}

.iconfont {
  margin: 0px 10px;
}

.sidebar-title {
  display: inline-block;
  margin: 10px;
  font-weight: 600;
  line-height: 50px;
  font-size: 20px;
  font-family: Avenir, Helvetica Neue, Arial, Helvetica, sans-serif;
  vertical-align: middle;
  max-width: 150px;
  height: 50px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
